package com.nhatviet.webservice;

import java.io.InputStream;
import java.io.StringReader;
import java.util.List;
import java.util.Vector;

import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;

import org.xml.sax.InputSource;
import org.xml.sax.XMLReader;

import com.nhatviet.webservice.helpers.XMLParserHandler;
import com.nhatviet.webservice.models.FlickrPhoto;


import android.app.AlertDialog;
import android.app.Application;
import android.content.Context;
import android.content.DialogInterface;

public class AppMain extends Application
{
	/* Common XML handlers*/
	public static List<XMLParserHandler> xmlParserHandlerList = new Vector<XMLParserHandler>();
	public static FlickrPhoto currentFlickrPhoto = null;
	/* Read the songs list data from a input stream */
	/**
	 * @param xmlParserHandler
	 * @param inputStream
	 * @throws Exception
	 */
	public static void readXMLData(XMLParserHandler xmlParserHandler, InputStream inputStream) throws Exception
	{
		/* Initiate the XML reader */
		SAXParserFactory parserFactory = SAXParserFactory.newInstance();
		SAXParser parser = parserFactory.newSAXParser();
		XMLReader xmlReader = parser.getXMLReader();
		xmlReader.setContentHandler(xmlParserHandler);

		/* Using the XML reader parsing XML from an input stream */
		xmlReader.parse(new InputSource(inputStream));
	}
	/* Read the songs list data from a input stream */
	public static void readXMLData(XMLParserHandler xmlParserHandler, String xmlStr) throws Exception
	{
		/* Initiate the XML reader */
		SAXParserFactory parserFactory = SAXParserFactory.newInstance();
		SAXParser parser = parserFactory.newSAXParser();
		XMLReader xmlReader = parser.getXMLReader();
		xmlReader.setContentHandler(xmlParserHandler);

		/* Using the XML reader parsing XML from an input string */
		InputSource inputSource = new InputSource();
		inputSource.setCharacterStream(new StringReader(xmlStr));
		xmlReader.parse(inputSource);
	}
	
	public static void alert(Context context, String title, String message)
	{
		AlertDialog alert = new AlertDialog.Builder(context).create();
		alert.setTitle(title);
		alert.setMessage(message);
		alert.setButton("OK",
				new DialogInterface.OnClickListener() {
					public void onClick(DialogInterface dialog,
							int which)
					{
					}
				});
		alert.show();
	}
}
